<?php 
require_once 'BaseMySQLDAO.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../Entity/Domain/OrderdetailsDomain.php';
class OrderdetailsDAO extends BaseMySQLDAO
{
	public function __construct($context) {
		parent::__construct($context, OrderdetailsDomain::$CollectionName);
	}

	public function create($obj){
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "INSERT INTO orderdetails(orderDetailID,orderID,articleID,price,quantity,amount)
					VALUES	(
								".$obj->getOrderDetailID().",
								".$obj->getOrderID().",
								".$obj->getArticleID().",
								".$obj->getPrice().",
								".$obj->getQuantity().",
								".$obj->getAmount()."
							)";
		$this->getMySQLConnection()->mysqlData($inSQL);
		$this->getContext()->getDBTransaction()->closeTransaction();
	}

	public function deleteByOid($oid){
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "DELETE FROM orderdetails WHERE orderDetailID=".$oid;
		$this->getMySQLConnection()->mysqlData($inSQL);
		$this->getContext()->getDBTransaction()->closeTransaction();
	}

	public function update($obj){
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "UPDATE orderdetails
				SET
					orderdetails.orderID = ".$obj->getOrderID().",
					orderdetails.articleID = ".$obj->getArticleID().",
					orderdetails.price = ".$obj->getPrice().",
					orderdetails.quantity = ".$obj->getQuantity().",
					orderdetails.amount = ".$obj->getAmount()."
				 WHERE orderDetailID=".$obj->getOrderDetailID();
		$this->getMySQLConnection()->mysqlData($inSQL);
		$this->getContext()->getDBTransaction()->closeTransaction();
	}

	public function findByOid($oid)
	{
		$orderdetailsDomain = null;
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "SELECT * FROM orderdetails WHERE orderdetails.orderDetailID = ".$oid;
		$res = $this->getMySQLConnection()->mysqlOneRow($inSQL);
		if($res)
		{
			$orderdetailsDomain = new OrderdetailsDomain($res);
		}
		$this->getContext()->getDBTransaction()->closeTransaction();
		return $orderdetailsDomain;
	}

	public function findAll()
	{
		$orderdetailsDomainArr = array();
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "SELECT * FROM orderdetails";
		$res = $this->getMySQLConnection()->mysqlData($inSQL);
		if($res)
		{
			while ($data = mysql_fetch_assoc($res))
			{
				$orderdetailsDomain = new OrderdetailsDomain($data);
				$orderdetailsDomainArr[] = $orderdetailsDomain;
			}
		}
		$this->getContext()->getDBTransaction()->closeTransaction();
		return $orderdetailsDomain;
	}

}
?>